local cjson = require "cjson"
local auth = require "auth"

ngx.req.read_body()
local body = ngx.req.get_body_data()
local data = cjson.decode(body)

local user_id, message = auth.login(data.username, data.password)

if user_id then
    ngx.say(cjson.encode({success = true, user_id = user_id, message = message}))
else
    ngx.status = 401
    ngx.say(cjson.encode({success = false, message = message}))
end
